package ru.spb.bragnikita.myevents.ibatis.runners;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import java.sql.*;

/**
 * @author Nikita.Brazhnikov
 */
public class JDBCRunner {

	private static final Logger logger = Logger.getLogger(JDBCRunner.class.getName());

	public static void main(String[] args) {
		logger.log(Level.DEBUG, "Test");
		PreparedStatement preparedStatement = null;
		Connection connection = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/myevents", "myevents", "myevents");
			preparedStatement = connection.prepareStatement("SELECT * FROM authors");
			final ResultSet resultSet = preparedStatement.executeQuery();
			while (resultSet.next()) {
				System.out.println("Author " + resultSet.getString("firstname") + " " + resultSet.getString("lastname"));
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
		} finally {
			try {
				preparedStatement.close();
				connection.close();
			} catch (SQLException e) {
				e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
			}

		}


	}


}
